<template>
  <div class="report-form-content">
    <div class="tabs-form-head">
      <span>合同借阅记录</span>
      <div class="">
        <el-button type="primary" plain @click="returnBtn">返回</el-button>
      </div>
    </div>
    <el-card class="update-log">
      <el-table :data="contractInitialBorrowList"
                style="width: 100%;
                margin-top: 20px"
                row-key="id"
                border
                default-expand-all>
        <el-table-column align="center" type="index" label="序号" width="60px" />
        <el-table-column v-if="isDebug" align="center" label="ID" prop="id" width="60px" sortable show-overflow-tooltip />
        <el-table-column align="center" label="合同编码" prop="code" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ contractInitial.code }}</template>
        </el-table-column>
        <el-table-column align="center" label="合同名称" prop="name" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ contractInitial.name  }}</template>
        </el-table-column>
        <el-table-column align="center" label="借阅类型" prop="borrowType" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.borrowType === '1' ? '纸质' : '电子'  }}</template>
        </el-table-column>
        <el-table-column align="center" label="借阅人" prop="borrowUserId" sortable show-overflow-tooltip>
          <template v-slot="{row}"><LabelTag :foreignList="userList" :foreignIds="row.borrowUserId" :foreignLabel="'name'" /></template>
        </el-table-column>
        <el-table-column align="center" label="借阅状态" prop="state" sortable show-overflow-tooltip>
          <template v-slot="{row}">
            <EnumTag :enum-list="getEnumList('ContractInitialBorrowType')" :enum-key="row.state" />
          </template>
          <!-- <template v-slot="{row}">{{ row.state }}</template> -->
        </el-table-column>
        <el-table-column align="center" label="备注" prop="borrowUserId" sortable show-overflow-tooltip>
          <template v-slot="{row}">{{ row.remark }}</template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>
<script setup>
import {getCurrentInstance, ref} from 'vue'
import {doGet} from "@/config/http";
import {svc, getListPageSize, getEnumList} from "@/config/common";
import { useRoute } from 'vue-router'
import initListStore from '@/store/modules/initList'

const route = useRoute()

const { proxy: ctx } = getCurrentInstance();

let contractInitial = ref(null)
let contractInitialBorrowList = ref([])

let userList = initListStore().userList // 用户
// const initList = async () => {
//   let p1 = doGet(svc, '/contract-type/page', {pageSize: getListPageSize()}, false) // 合同类型
//   let p2 = doGet(svc, '/contract-cooperation/page', {pageSize: getListPageSize()}, false) // 往来单位
//   let p3 = doGet(svc, '/contract-feetype/page', {pageSize: getListPageSize()}, false) // 合同费用类型
//   let p4 = doGet(svc, '/contract-template/page', {pageSize: getListPageSize()}, false) // 合同模版
//   let p5 = doGet(svc, '/bank/page', {pageSize: getListPageSize()}, false) // 银行
//   let p6 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false) // 用户
//   let p7 = doGet(svc, '/government/page', {pageSize: getListPageSize()}, false) //  政府单位
//   let p8 = doGet(svc, '/organization/page', {pageSize: getListPageSize()}, false) // 部门
//   let p9 = doGet(svc, '/contract-signer/page', {pageSize: getListPageSize()}, false) // 签订人
//   let p10 = doGet(svc, '/contract-filetype/page', {pageSize: getListPageSize()}, false) // 合同附件类型

//   let resArray = await Promise.all([p1, p2, p3, p4, p5, p6, p7, p8, p9, p10])
//   contractTypeList.value = resArray[0]['records']
//   contractCooperationList.value = resArray[1]['records']
//   contractFeetypeList.value = resArray[2]['records']
//   contractTemplateList.value = resArray[3]['records']
//   bankList.value = resArray[4]['records']
//   userList.value = resArray[5]['records']
//   governmentList.value = resArray[6]['records']
//   organizationList.value = resArray[7]['records']
//   contractSignerList.value = resArray[8]['records']
//   contractFiletypeList.value = resArray[9]['records']
// }
const initObj = async () =>  {
  if (route.query.id) {
    contractInitial.value = await doGet(svc, '/contract-initial/' + route.query.id, {}, false)
    contractInitialBorrowList.value = await doGet(svc, '/contract-initial-borrow/listByField', {field: 'contractInitialId', values: route.query.id}, true)
  }
}
initObj()
// initList()

const returnBtn = () => {
  switch (route.query.kind) {
    case '1':
      ctx.goTargetByName('contractInitial', {});
      break;
    case '2':
      ctx.goTargetByName('contractMain', {})
      break;
  }
}

</script>
<style scoped>
.report-form-content {
  padding: 20px;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.tabs-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tabs-form-head span {
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}
</style>
